package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertPrimitiveArrayToObjectArray {
	public static void main(String[] argv) {
		Object value = "www.tah1986.com";
		System.out.println(java.util.Arrays
				.toString(convertPrimitiveArrayToObjectArray(value)));
	}

	public static Object[] convertPrimitiveArrayToObjectArray(Object value) {
		if (value instanceof int[]) {
			return toPrimitiveArray((int[]) value);
		} else if (value instanceof long[]) {
			return toPrimitiveArray((long[]) value);
		} else if (value instanceof short[]) {
			return toPrimitiveArray((short[]) value);
		} else if (value instanceof float[]) {
			return toPrimitiveArray((float[]) value);
		} else if (value instanceof double[]) {
			return toPrimitiveArray((double[]) value);
		} else if (value instanceof char[]) {
			return toPrimitiveArray((char[]) value);
		} else if (value instanceof byte[]) {
			return toPrimitiveArray((byte[]) value);
		} else if (value instanceof boolean[]) {
			return toPrimitiveArray((boolean[]) value);
		} else if (value instanceof Object[]) {
			return (Object[]) value;
		} else {
			throw new RuntimeException("object 不是数组.");
		}
	}

	private static Object[] toPrimitiveArray(char values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Character value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(float values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Float value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(long values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Long value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(short values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Short value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(int values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Integer value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(double values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Double value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(boolean values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Boolean value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}

	private static Object[] toPrimitiveArray(byte values[]) {
		List<Object> objs = new ArrayList<Object>();
		for (Byte value : values) {
			objs.add(value);
		}
		return objs.toArray();
	}
}
